home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0013_Crynrware Packet Driver Interface.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  15.0 KB  |  549 lines

  1. UNIT PKTDRVR;
  2. {
  3. ╔════════════════════════════════╤═════════════════════════════════════╗
  4. ║ Filename       : PKTDRVR.PAS   │  Program / Unit : [U]               ║
  5. ║ Description    : Turbo Pascal  └─────────────────────────────────────╢
  6. ║                  Object to interface with Crynrware packet drivers.  ║
  7. ║                                                                      ║
  8. ╟──────────────────────────────────────────────────────────────────────╢
  9. ║ Compiler       : Turbo Pascal 7.0                                    ║
  10. ║ OS-Version     : MS-DOS 6.0                                          ║
  11. ║ Last edit      : 08-Oct-93                                           ║
  12. ║ Version        : 1.0                                                 ║
  13. ╟──────────────────────────────────────────────────────────────────────╢
  14. ║ Author         : Oliver Rehmann                                      ║
  15. ║ Copyright      : (C) 1993 Oliver Rehmann                             ║
  16. ║                                                                      ║
  17. ║ Released to public domain.                                           ║
  18. ║ The author can not be held responsible for any damages resulting     ║
  19. ║ from the use of this software.                                       ║
  20. ╚══════════════════════════════════════════════════════════════════════╝
  21. }
  22.  
  23. INTERFACE
  24.  
  25. USES
  26.   DOS,OBJECTS;
  27.  
  28. CONST
  29.   { Packet driver interface classes }
  30.   CL_NONE           = 0;
  31.   CL_ETHERNET     = 1;
  32.   CL_PRONET_10    = 2;
  33.   CL_IEEE8025       = 3;
  34.   CL_OMNINET        = 4;
  35.   CL_APPLETALK    = 5;
  36.   CL_SERIAL_LINE    = 6;
  37.   CL_STARLAN        = 7;
  38.   CL_ARCNET       = 8;
  39.   CL_AX25             = 9;
  40.   CL_KISS             = 10;
  41.   CL_IEEE8023       = 11;
  42.   CL_FDDI         = 12;
  43.   CL_INTERNET_X25 = 13;
  44.   CL_LANSTAR        = 14;
  45.   CL_SLFP         = 15;
  46.   CL_NETROM       = 16;
  47.   NCLASS              = 17;
  48.  
  49.   { Packet driver interface types (not a complete list) }
  50.   TC500             = 1;
  51.   PC2000              = 10;
  52.   WD8003              = 14;
  53.   PC8250              = 15;
  54.   ANYTYPE             = $ffff;
  55.  
  56.   { Packet driver function call numbers. From Appendix B. }
  57.   DRIVER_INFO         = 1;
  58.   ACCESS_TYPE         = 2;
  59.   RELEASE_TYPE      = 3;
  60.   SEND_PKT          = 4;
  61.   TERMINATE         = 5;
  62.   GET_ADDRESS         = 6;
  63.   RESET_INTERFACE   = 7;
  64.   GET_PARAMETERS    = 10;
  65.   AS_SEND_PKT         = 11;
  66.   SET_RCV_MODE      = 20;
  67.   GET_RCV_MODE      = 21;
  68.   SET_MULTICAST_LIST    = 22;
  69.   GET_MULTICAST_LIST    = 23;
  70.   GET_STATISTICS          = 24;
  71.   SET_ADDRESS             = 25;
  72.  
  73.   { Packet driver error return codes. From Appendix C. }
  74.   NO_ERROR        = 0;
  75.   BAD_HANDLE        = 1;    { invalid handle number }
  76.   NO_CLASS        = 2;  { no interfaces of specified class found }
  77.   NO_TYPE             = 3;  { no interfaces of specified type found }
  78.   NO_NUMBER       = 4;  { no interfaces of specified number found }
  79.   BAD_TYPE        = 5;  { bad packet type specified }
  80.   NO_MULTICAST    = 6;  { this interface does not support multicast }
  81.   CANT_TERMINATE    = 7;    { this packet driver cannot terminate }
  82.   BAD_MODE        = 8;  { an invalid receiver mode was specified }
  83.   NO_SPACE        = 9;  { operation failed because of insufficient space }
  84.   TYPE_INUSE        = 10;   { the type had previously been accessed, and not
  85. released } BAD_COMMAND       = 11;   { the command was out of range, or not 
  86. implemented } CANT_SEND       = 12; { the packet couldn't be sent (usually 
  87. hardware error) } CANT_SET        = 13; { hardware address couldn't be changed
  88. (> 1 handle open) } BAD_ADDRESS       = 14;   { hardware address has bad
  89. length or format } CANT_RESET        = 15;   { couldn't reset interface (> 1
  90. handle open) }
  91.  
  92.   CARRY_FLAG        = 1;
  93.  
  94. CONST
  95.   Pkt_Sig  : String[08] = 'PKT DRVR';
  96.   ParamLen : Byte       = 14;
  97.  
  98. TYPE
  99.   TPKTSTATUS  = (NO_PKTDRVR,INITIALIZED,NOT_INITIALIZED);
  100.   TACCESSTYPE = RECORD
  101.       if_class      : Byte;    { Interface class  }
  102.         if_type       : Word;    { Interface Type   }
  103.         if_number     : Byte;    { Interface number }
  104.         type_         : Pointer;
  105.         typelen       : Word;    { length of type_, set to 0 if
  106.                                    you want to receive all pkts }
  107.         receiver      : Pointer; { receive handler }
  108.     END;
  109.  
  110.   TPKTPARAMS   = RECORD
  111.       major_rev     : Byte; { Major revision ID of packet specs }
  112.         minor_rev     : Byte; { Minor revision ID of packet specs }
  113.         length        : Byte; { Length of structure in Bytes      }
  114.         addr_len      : Byte; { Length of a MAC address           }
  115.         mtu           : Word; { MTU, including MAC headers        }
  116.         multicast_aval: Word; { buffer size for multicast addr.   }
  117.         rcv_bufs      : Word; { (# of back-to-back MTU rcvs) - 1  }
  118.         xmt_bufs      : Word; { (# of successive xmits) - 1       }
  119.         int_num       : Word; { Interrupt # to hook for post-EOI
  120.                                       processing, 0 == none }
  121.   END;
  122.  
  123.   TDRVRINFO    = RECORD
  124.       Version       : Word; { Packet driver version   }
  125.         Class         : Byte; { Driver class  }
  126.         Type_         : Word; { Driver type   }
  127.         Number        : Byte; { Driver number }
  128.         pName         : Pointer;
  129.         Functionality : Byte; { How good is this driver }
  130.     END;
  131.  
  132.   TSTATISTICS = RECORD
  133.       packets_in    : LongInt;
  134.         packets_out   : LongInt;
  135.         bytes_in      : LongInt;
  136.         bytes_out     : LongInt;
  137.         errors_in     : LongInt;
  138.         errors_out    : LongInt;
  139.         packets_lost  : LongInt;
  140.     END;
  141.  
  142.   TPKTDRVR = OBJECT(TOBJECT)
  143.     private
  144.         pktInt         : Integer;
  145.         pktHandle      : Integer;
  146.         pktRecvHandler : Pointer;
  147.         pktStatus      : TPKTSTATUS;
  148.         pktError       : Byte;
  149.         pktRegs        : Registers;
  150.  
  151.         pktAccessInfo  : TACCESSTYPE;
  152.  
  153.         PROCEDURE   TestForPktDriver;
  154.  
  155.     public
  156.         CONSTRUCTOR Init(IntNo : Integer);
  157.         DESTRUCTOR  Done; VIRTUAL;
  158.  
  159.         PROCEDURE   ScanForPktDriver;
  160.  
  161.         FUNCTION    GetStatus                          : TPKTSTATUS;
  162.         FUNCTION    GetError                           : Byte;
  163.         FUNCTION    GetHandle                          : Word;
  164.  
  165.         PROCEDURE   GetAccessType   (VAR pktAccessType : TACCESSTYPE);
  166.         PROCEDURE   DriverInfo      (VAR pktInfo       : TDRVRINFO  );
  167.  
  168.         PROCEDURE   AccessType      (VAR pktAccessType : TACCESSTYPE);
  169.         PROCEDURE   ReleaseType;
  170.         PROCEDURE   TerminateDriver;
  171.  
  172.         PROCEDURE   GetAddress      (Buffer : Pointer;BufLen : Word; VAR
  173. BufCopied : Word); PROCEDURE ResetInterface; PROCEDURE   GetParameters   (VAR
  174. pktParams : TPKTPARAMS);
  175.  
  176.         PROCEDURE   SendPkt         (Buffer : Pointer;BufLen : Word );
  177.         PROCEDURE   As_SendPkt      (Buffer : Pointer;BufLen : Word;Upcall :
  178. Pointer     );
  179.  
  180.         PROCEDURE   SetRCVmode      (Mode   : Word);
  181.         FUNCTION    GetRCVmode              : Word;
  182.  
  183.         PROCEDURE   SetMulticastList(VAR mcList : Pointer; VAR mcLen : Word);
  184.         PROCEDURE   GetMulticastList(VAR mcList : Pointer; VAR mcLen : Word);
  185.  
  186.         PROCEDURE   GetStatistics   (VAR pktStatistics : TSTATISTICS       );
  187.         PROCEDURE   SetAddress      (Address : Pointer; VAR AddrLen  : Word);
  188.   END;
  189.  
  190.  
  191. IMPLEMENTATION
  192. CONSTRUCTOR TPKTDRVR.Init(IntNo : Integer);
  193. BEGIN
  194.   Inherited Init;
  195.  
  196.   pktInt    := IntNo;
  197.   pktStatus := NOT_INITIALIZED;
  198.   FillChar(pktAccessInfo,SizeOf(pktAccessInfo),#00);
  199.  
  200.   TestForPktDriver;
  201. END;
  202.  
  203.  
  204. DESTRUCTOR TPKTDRVR.Done;
  205. BEGIN
  206.   { Release allocated handle }
  207.   IF (pktStatus = INITIALIZED) THEN
  208.   BEGIN
  209.     ReleaseType;
  210.   END;
  211.  
  212.   Inherited Done;
  213. END;
  214.  
  215.  
  216. FUNCTION TPKTDRVR.GetStatus : TPKTSTATUS;
  217. BEGIN
  218.   GetStatus := pktStatus;
  219. END;
  220.  
  221. PROCEDURE TPKTDRVR.GetAccessType(VAR pktAccessType : TACCESSTYPE);
  222. BEGIN
  223.   pktAccessType := pktAccessInfo;
  224. END;
  225.  
  226. PROCEDURE TPKTDRVR.TestForPktDriver;
  227. (* Tests if the assigned interrupt points to a valid packet driver. *)
  228. VAR tPointer  : Pointer;
  229.     Signature : String[08];
  230.     I         : Integer;
  231. BEGIN
  232.   Signature := '';
  233.   GetIntVec(pktInt,tPointer);
  234.   FOR I := 3 TO 10 DO
  235.   BEGIN
  236.     Signature := Signature + Chr(Mem[Seg(tPointer^):Ofs(tPointer^)+I]);
  237.   END;
  238.   IF (POS(Pkt_Sig,Signature) = 0) THEN
  239.     pktStatus := NO_PKTDRVR
  240.   ELSE
  241.     pktStatus := INITIALIZED;
  242. END;
  243.  
  244. PROCEDURE TPKTDRVR.ScanForPktDriver;
  245. (* Scans interrupts ($60-$7F) for a packet driver. *)
  246. (* Stops if it has found a valid driver.           *)
  247. VAR I : Integer;
  248. BEGIN
  249.   I := $60; { Lower range of possible pktdrvr interrupt }
  250.   REPEAT
  251.     pktInt := I;
  252.     TestForPktDriver;
  253.     Inc(I);
  254.   UNTIL (I = $80) OR (pktStatus = INITIALIZED);
  255. END;
  256.  
  257. PROCEDURE TPKTDRVR.DriverInfo(VAR pktInfo : TDRVRINFO);
  258. BEGIN
  259.   WITH pktRegs DO
  260.   BEGIN
  261.     AH := DRIVER_INFO;
  262.     AL := $FF;
  263.     BX := pktHandle;
  264.     Intr(pktInt,pktRegs); { Call Packet Driver }
  265.     IF (pktRegs.Flags AND Carry_Flag) = Carry_Flag THEN
  266.       pktError := DH
  267.     ELSE
  268.     BEGIN
  269.       pktError := 0;
  270.       IF (pktError = NO_ERROR) THEN
  271.       BEGIN
  272.     pktInfo.Version       := BX;
  273.     pktInfo.Class         := CH;
  274.     pktInfo.Type_         := DX;
  275.     pktInfo.Number        := CL;
  276.     pktInfo.pName         := Ptr(DS,SI);
  277.     pktInfo.Functionality := AL;
  278.       END;
  279.     END;
  280.   END;
  281. END;
  282.  
  283. PROCEDURE TPKTDRVR.AccessType(VAR pktAccessType : TACCESSTYPE);
  284. (* Accesses the packet driver.  *)
  285. BEGIN
  286.   WITH pktRegs DO
  287.   BEGIN
  288.     AH := ACCESS_TYPE;
  289.     AL := pktAccessType.if_class;
  290.     BX := pktAccessType.if_type;
  291.     CX := pktAccessType.typelen;
  292.     DL := pktAccessType.if_number;
  293.     DS := Seg(pktAccessType.type_^);
  294.     SI := Ofs(pktAccessType.type_^);
  295.     ES := Seg(pktAccessType.receiver^);
  296.     DI := Ofs(pktAccessType.receiver^);
  297.     Intr(pktInt,pktRegs);
  298.     IF (Flags AND Carry_Flag) = Carry_Flag THEN
  299.       pktError      := DH
  300.     ELSE
  301.     BEGIN
  302.       pktError      := 0;
  303.       pktHandle     := AX;
  304.       pktAccessInfo := pktAccessType;
  305.     END;
  306.   END;
  307. END;
  308.  
  309. PROCEDURE TPKTDRVR.ReleaseType;
  310. (* Releases a specific type handle *)
  311. BEGIN
  312.   WITH pktRegs DO
  313.   BEGIN
  314.     AH := RELEASE_TYPE;
  315.     BX := pktHandle;
  316.     Intr(pktInt,pktRegs);
  317.     IF (Flags AND Carry_Flag) = Carry_Flag THEN
  318.       pktError := DH
  319.     ELSE
  320.       pktError := 0;
  321.   END;
  322. END;
  323.  
  324. PROCEDURE TPKTDRVR.SendPkt(Buffer : Pointer;BufLen : Word);
  325. BEGIN
  326.   WITH pktRegs DO
  327.   BEGIN
  328.     AH := SEND_PKT;
  329.     CX := BufLen;
  330.     DS := Seg(Buffer^);
  331.     ES := DS;
  332.     SI := Ofs(Buffer^);
  333.     Intr(pktInt,pktRegs);
  334.     IF (Flags AND Carry_Flag) = Carry_Flag THEN
  335.       pktError := DH
  336.     ELSE
  337.       pktError := 0;
  338.   END;
  339. END;
  340.  
  341. PROCEDURE   TPKTDRVR.TerminateDriver;
  342. (* Terminates the Driver associated with pktHandle *)
  343. BEGIN
  344.   WITH pktRegs DO
  345.   BEGIN
  346.     AH := TERMINATE;
  347.     BX := pktHandle;
  348.     Intr(pktInt,pktRegs);
  349.     IF (Flags AND Carry_Flag) = Carry_Flag THEN
  350.       pktError := DH
  351.     ELSE
  352.       pktError := 0;
  353.   END;
  354. END;
  355.  
  356. PROCEDURE TPKTDRVR.GetAddress (Buffer : Pointer;BufLen : Word; VAR BufCopied :
  357. Word);
  358. BEGIN
  359.   WITH pktRegs DO
  360.   BEGIN
  361.     AH := GET_ADDRESS;
  362.     BX := pktHandle;
  363.     CX := BufLen;
  364.     ES := Seg(Buffer^);
  365.     DI := Ofs(Buffer^);
  366.     Intr(pktInt,pktRegs);
  367.     IF (Flags AND Carry_Flag) = Carry_Flag THEN
  368.       pktError  := DH
  369.     ELSE
  370.     BEGIN
  371.       pktError  := 0;
  372.       BufCopied := CX;
  373.     END;
  374.   END;
  375. END;
  376.  
  377. PROCEDURE TPKTDRVR.ResetInterface;
  378. BEGIN
  379.   WITH pktRegs DO
  380.   BEGIN
  381.     AH := RESET_INTERFACE;
  382.     BX := pktHandle;
  383.     Intr(pktInt,pktRegs);
  384.     IF (Flags AND Carry_Flag) = Carry_Flag THEN
  385.       pktError := DH
  386.     ELSE
  387.       pktError := 0;
  388.   END;
  389. END;
  390.  
  391. PROCEDURE TPKTDRVR.GetParameters(VAR pktParams : TPKTPARAMS);
  392. (* Description   : │ Gets specific parameters from the driver. *)
  393. (* Not all drivers support this function.                      *)
  394. VAR b : Byte;
  395. BEGIN
  396.   WITH pktRegs DO
  397.   BEGIN
  398.     AH := GET_PARAMETERS;
  399.     Intr(pktInt,pktRegs);
  400.     IF (Flags AND Carry_Flag) = Carry_Flag THEN
  401.       pktError := DH
  402.     ELSE
  403.     BEGIN
  404.       pktError := 0;
  405.       FOR b := 0 TO ParamLen-1 DO  { Copy contents of structure }
  406.     Mem[Seg(pktParams):Ofs(PktParams)+b] := Mem[ES:DI+b];
  407.     END;
  408.   END;
  409. END;
  410.  
  411.  
  412. PROCEDURE TPKTDRVR.As_SendPkt(Buffer : Pointer;BufLen : Word;Upcall :
  413. Pointer);
  414. (* Sends a data packet by accessing the packet driver.  *)
  415. (* Upcall is called when order was placed.              *)
  416. BEGIN
  417.   WITH pktRegs DO
  418.   BEGIN
  419.     AH := AS_SEND_PKT;
  420.     CX := BufLen;
  421.     DS := Seg(Buffer);
  422.     SI := Ofs(Buffer);
  423.     ES := Seg(Upcall^);
  424.     DI := Ofs(Upcall^);
  425.     Intr(pktInt,pktRegs);
  426.     IF (Flags AND Carry_Flag) = Carry_Flag THEN
  427.       pktError := DH
  428.     ELSE
  429.       pktError := 0;
  430.   END;
  431. END;
  432.  
  433. PROCEDURE TPKTDRVR.SetRCVmode(Mode : Word);
  434.  
  435. BEGIN
  436.   WITH pktRegs DO
  437.   BEGIN
  438.     AH := SET_RCV_MODE;
  439.     BX := pktHandle;
  440.     CX := Mode;
  441.     Intr(pktInt,pktRegs);
  442.     IF (Flags AND Carry_Flag) = Carry_Flag THEN
  443.       pktError := DH
  444.     ELSE
  445.       pktError := 0;
  446.   END;
  447. END;
  448.  
  449. FUNCTION TPKTDRVR.GetRCVmode : Word;
  450. BEGIN
  451.   WITH pktRegs DO
  452.   BEGIN
  453.     AH := GET_RCV_MODE;
  454.     BX := pktHandle;
  455.     Intr(pktInt,pktRegs);
  456.     IF (Flags AND Carry_Flag) = Carry_Flag THEN
  457.       pktError   := DH
  458.     ELSE
  459.     BEGIN
  460.       pktError   := 0;
  461.       GetRCVmode := AX;
  462.     END;
  463.   END;
  464. END;
  465.  
  466. PROCEDURE TPKTDRVR.SetMulticastList(VAR mcList : Pointer; VAR mcLen : Word);
  467. BEGIN
  468.   WITH pktRegs DO
  469.   BEGIN
  470.     AH := SET_MULTICAST_LIST;
  471.     CX := mcLen;
  472.     ES := Seg(mcList^);
  473.     DI := Ofs(mcList^);
  474.     Intr(pktInt,pktRegs);
  475.     IF (Flags AND Carry_Flag) = Carry_Flag THEN
  476.       pktError := DH
  477.     ELSE
  478.       pktError := 0;
  479.   END;
  480. END;
  481.  
  482. PROCEDURE TPKTDRVR.GetMulticastList(VAR mcList : Pointer; VAR mcLen : Word);
  483. BEGIN
  484.   WITH pktRegs DO
  485.   BEGIN
  486.     AH := GET_MULTICAST_LIST;
  487.     Intr(pktInt,pktRegs);
  488.     IF (Flags AND Carry_Flag) = Carry_Flag THEN
  489.       pktError := DH
  490.     ELSE
  491.     BEGIN
  492.       pktError := 0;
  493.       mcList   := Ptr(ES,DI);
  494.       mcLen    := CX;
  495.     END;
  496.   END;
  497. END;
  498.  
  499. PROCEDURE TPKTDRVR.GetStatistics(VAR pktStatistics : TSTATISTICS);
  500. VAR b : Byte;
  501. BEGIN
  502.   WITH pktRegs DO
  503.   BEGIN
  504.     AH := GET_STATISTICS;
  505.     Intr(pktInt,pktRegs);
  506.     IF (Flags AND Carry_Flag) = Carry_Flag THEN
  507.       pktError := DH
  508.     ELSE
  509.     BEGIN
  510.       pktError := 0;
  511.       FOR b := 0 TO SizeOf(TSTATISTICS)-1 DO  { Copy contents of structure }
  512.     Mem[Seg(pktStatistics):Ofs(pktStatistics)+b] := Mem[DS:SI+b];
  513.     END;
  514.   END;
  515. END;
  516.  
  517. PROCEDURE TPKTDRVR.SetAddress(Address : Pointer; VAR AddrLen : Word);
  518. BEGIN
  519.   WITH pktRegs DO
  520.   BEGIN
  521.     AH := SET_ADDRESS;
  522.     CX := AddrLen;
  523.     ES := Seg(Address^);
  524.     DI := Ofs(Address^);
  525.     Intr(pktInt,pktRegs);
  526.     IF (Flags AND Carry_Flag) = Carry_Flag THEN
  527.       pktError := DH
  528.     ELSE
  529.     BEGIN
  530.       pktError := 0;
  531.       AddrLen  := CX;
  532.     END;
  533.   END;
  534. END;
  535.  
  536. FUNCTION TPKTDRVR.GetError  : Byte;
  537. BEGIN
  538.   GetError := pktError;
  539. END;
  540.  
  541. FUNCTION TPKTDRVR.GetHandle : Word;
  542. BEGIN
  543.   GetHandle := pktHandle;
  544. END;
  545.  
  546. BEGIN
  547. END.
  548. {end}
  549.